#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

ll qmi(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n == 2)
    {
        cout << stoi(s) << endl;
        return;
    }
    else if(n == 3)
    {
        if(s[0] == '0' || s[2] == '0')
        {
            cout << 0 << endl;
            return;
        }
        int a = s[0] - '0',  b = stoi(s.substr(1, 2));
        int c = stoi(s.substr(0, 2)), d = s[2] - '0';
        cout << min({a + b, a * b, c + d, c * d}) << endl;
        return;
    }
    else
    {
        int res = INT_MAX;
        for(int i = 0; i < n - 1; i++)
        {
            if(s[i] == '0' || s[i + 1] == '0')
            {
                cout << 0 << endl;
                return ;
            }
            int st = 1;
            int ans = 0;
            int p = i;
            if(p == 0)
            {
                st = 2;
                ans = stoi(s.substr(0, 2));
            }
            else ans = s[0] - '0';
            for(int j = st; j < n; j++)
            {
                if(j == p)
                {
                    if(ans == 1) ans = stoi(s.substr(j, 2));
                    else ans += stoi(s.substr(j, 2));
                    j++;
                    continue;
                }
                if(ans == 1)
                {
                    ans = s[j] - '0';
                }
                else if(s[j] != '1')
                {
                    ans += (s[j] - '0');
                }
            }
            res = min(ans, res);
        }

        cout << res << endl;
    }
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}